package com.ruoyi.system.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.Temperature;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@DS("TDengine")
public interface TemperatureMapper extends BaseMapper<Temperature> {

    @Insert("  CREATE STABLE if not exists temperature(ts timestamp, temperature float) " +
        "   tags(location nchar(64), tb_index int) ")
    int createSuperTable();

    @Insert("create table ${tbName} using temperature tags( '${location}', ${tbindex})")
    int createTable(@Param("tbName") String tbName, @Param("location") String location, @Param("tbindex") int tbindex);

    @Update("drop STABLE if exists temperature")
    void dropSuperTable();

    @Insert("insert into t${tbIndex}(ts, temperature) values(#{ts}, #{temperature})")
    int insertOne(Temperature one);

    @Select("select * from meters  order by ts desc  limit 1000 ")
    List<Map> ssss( );

    @Select("select * from   temperature order by ts desc  limit #{data} ")
    List<Map> ssss22( @Param("data") Integer data);
    @Select("select * from   airplane_supper order by ts desc  limit #{data} ")
    List<Map> ssssPlane2( @Param("data") Integer data);
    @Select("select * from   airport_supper order by ts desc  limit #{data} ")
    List<Map> ssssPort2( @Param("data") Integer data);
    @Select("select * from   airport_supper order by ts desc  limit #{data} ")
    List<Map> ssssPort( @Param("data") Integer data);


}
